import { ajaxService } from '@/utils/request';
import * as typeObj from './type';

const env = import.meta.env;
let baseURL = env.VITE_FACTORY_URL;
let userURL = env.VITE_TAOGESHABI_URL;

/**新增工序组 */
export function AddWorkSerialGroup(data: typeObj.TWorkSerialGroup) {
  return ajaxService({
    url: '/factory/process/group',
    method: 'post',
    data,
    successMsg: '新增成功',
    baseURL,
  });
}
/**新增工序组 */
export function EditWorkSerialGroup(data: typeObj.TWorkSerialGroup) {
  return ajaxService({
    url: '/factory/process/group',
    method: 'put',
    data,
    successMsg: '修改成功',
    baseURL,
  });
}

/**获取工序组 */
export function GetWorkSerialGroup(data: any) {
  return ajaxService({
    url: '/factory/process/group',
    method: 'get',
    params: data,
    baseURL,
  });
}

/**获取工序分页组 */
export function GetWorkSerialGroupPage(data: any) {
  return ajaxService({
    url: '/factory/process/group/page',
    method: 'get',
    params: data,
    baseURL,
  });
}

/**删除工序组 */
export function DelWorkSerialGroup(data: any) {
  return ajaxService({
    url: '/factory/process/group',
    method: 'delete',
    data,
    successMsg: '删除成功',
    baseURL,
  });
}

/**新增工艺路线 */
export function AddProcessRoute(data: any) {
  return ajaxService({
    url: '/factory/technology',
    method: 'post',
    data,
    successMsg: '新增成功',
    baseURL,
  });
}
/**修改工艺路线 */
export function EditProcessRoute(data: typeObj.TWorkSerialGroup) {
  return ajaxService({
    url: '/factory/technology',
    method: 'put',
    data,
    successMsg: '修改成功',
    baseURL,
  });
}

/**获取工艺路线 */
export function GetProcessRoute(data: any) {
  return ajaxService({
    url: '/factory/technology',
    method: 'get',
    params: data,
    baseURL,
  });
}

/**获取工艺路线 */
export function GetProcessRoutePage(data: any) {
  return ajaxService({
    url: '/factory/technology/page',
    method: 'get',
    params: data,
    baseURL,
  });
}

/**删除工艺路线 */
export function DelProcessRoute(data: any) {
  return ajaxService({
    url: '/factory/technology',
    method: 'delete',
    successMsg: '删除成功',
    data,
    baseURL,
  });
}

/**新增产品工艺路线 */
export function AddProductProcessRoute(data: typeObj.TProductProcessRoute) {
  return ajaxService({
    url: '/factory/product',
    method: 'post',
    data,
    successMsg: '新增成功',
    baseURL,
  });
}
/**修改产品工艺路线 */
export function EditProductProcessRoute(data: typeObj.TProductProcessRoute) {
  return ajaxService({
    url: '/factory/product',
    method: 'put',
    data,
    successMsg: '修改成功',
    baseURL,
  });
}

/**获取产品工艺路线 */
export function GetProductProcessRoute(data: any) {
  return ajaxService({
    url: '/factory/product',
    method: 'get',
    params: data,
    baseURL,
  });
}

/**获取产品工艺路线 */
export function GetProductProcessRoutePage(data: any) {
  return ajaxService({
    url: '/factory/product/page',
    method: 'get',
    params: data,
    baseURL: userURL,
  });
}
/**更改产品工艺路线不可删除 */
export function ChangeProductProcessRoutState(id: any) {
  return ajaxService({
    url: '/factory/product/state',
    method: 'put',
    data: { id },
    baseURL: userURL,
  });
}
/**删除产品工艺路线 */
export function DelProductProcessRoute(data: any) {
  return ajaxService({
    url: '/factory/product',
    method: 'delete',
    successMsg: '删除成功',
    params: data,
    baseURL,
  });
}

/**Sop分页 */
export function GetSetSopPage(params: any) {
  return ajaxService({
    url: '/factory/product/detail',
    method: 'get',
    params,
    baseURL,
  });
}

/**保存Sop */
export function SaveSetSop(data: typeObj.TSop) {
  return ajaxService({
    url: '/factory/sop',
    method: 'post',
    data,
    baseURL,
  });
}

/**删除Sop */
export function DelSetSop(data: any) {
  return ajaxService({
    url: '/factory/sop',
    method: 'delete',
    successMsg: '删除成功',
    data,
    baseURL,
  });
}
/**新增产品bom */
export function AddProductBom(data: typeObj.TbomBase) {
  return ajaxService({
    url: '/factory/product/bom',
    method: 'post',
    data,
    successMsg: '新增成功',
    baseURL,
  });
}
/**修改产品bom */
export function EditProductBom(data: typeObj.TbomBase) {
  return ajaxService({
    url: '/factory/product/bom',
    method: 'put',
    data,
    successMsg: '修改成功',
    baseURL,
  });
}

/**获取产品bom */
export function GetProductBom(data: any) {
  return ajaxService({
    url: '/factory/product/bom',
    method: 'get',
    params: data,
    baseURL,
  });
}

/**获取产品bom */
export function GetProductBomByIds(ids: any[]) {
  return ajaxService({
    url: '/factory/product/bom/batch',
    method: 'post',
    data: { ids },
    baseURL,
  });
}

/**获取产品bom */
export function GetProductBomPage(data: any) {
  return ajaxService({
    url: '/factory/product/bom/page',
    method: 'get',
    params: data,
    baseURL,
  });
}

/**删除产品bom */
export function DelProductBom(data: any) {
  return ajaxService({
    url: '/factory/product/bom',
    method: 'delete',
    successMsg: '删除成功',
    data,
    baseURL,
  });
}

/**获取产品bom */
export function GetProductBomTree(id: any) {
  return ajaxService({
    url: '/factory/product/bom/tree',
    method: 'get',
    params: { id },
    baseURL,
  });
}

/**检查产品bom */
export function CheckProductBom(data: any) {
  return ajaxService({
    url: '/factory/check/bom/tree',
    method: 'get',
    params: data,
    baseURL,
  });
}
/**检查产品bom */
export function EditProductBomHistoryState(data: any) {
  return ajaxService({
    url: '/factory/product/detail/bom',
    method: 'put',
    data,
    baseURL,
  });
}
/**检查产品bom */
export function EditProductRoadHistoryState(data: any) {
  return ajaxService({
    url: '/factory/product/history/state',
    method: 'put',
    data,
    baseURL,
  });
}

/**获取车间 */
export function GetWorkshopPage(data: any) {
  return ajaxService({
    url: '/factory/workshop/page',
    method: 'get',
    params: data,
    baseURL,
  });
}

export function GetResourcesPage(data: any) {
  return ajaxService({
    url: '/factory/page/set',
    method: 'get',
    params: data,
    baseURL,
  });
}
export function GetFactoryResourcesPage(data: any) {
  return ajaxService({
    url: '/factory/page/resources',
    method: 'get',
    params: data,
    baseURL,
  });
}

/**获取车间 */
export function AddWorkshopPage(data: any) {
  return ajaxService({
    url: '/factory/workshop',
    method: 'post',
    successMsg: '新增成功',
    data,
    baseURL,
  });
}

/**删除车间 */
export function DelWorkshop(data: any) {
  return ajaxService({
    url: '/factory/workshop',
    method: 'delete',
    successMsg: '删除成功',
    data,
    baseURL,
  });
}

/**修改车间 */
export function EditWorkshop(data: typeObj.TbomBase) {
  return ajaxService({
    url: '/factory/workshop',
    method: 'post',
    data,
    successMsg: '修改成功',
    baseURL,
  });
}

/**获取工位 */
export function GetStationPage(data: any) {
  return ajaxService({
    url: '/factory/station/page',
    method: 'get',
    params: data,
    baseURL,
  });
}
/**获取工位*/
export function AddStation(data: any) {
  return ajaxService({
    url: '/factory/station',
    method: 'post',
    successMsg: '新增成功',
    data,
    baseURL,
  });
}

/**删除工位 */
export function DelStation(data: any) {
  return ajaxService({
    url: '/factory/station',
    method: 'delete',
    successMsg: '删除成功',
    data,
    baseURL,
  });
}

/**修改工位 */
export function EditStation(data: typeObj.TbomBase) {
  return ajaxService({
    url: '/factory/station',
    method: 'post',
    data,
    successMsg: '修改成功',
    baseURL,
  });
}

/**获取工位 */
export function GetProductionLinePage(data: any) {
  return ajaxService({
    url: '/factory/product/line/page',
    method: 'get',
    params: data,
    baseURL,
  });
}
/**获取工位*/
export function AddProductionLine(data: any) {
  return ajaxService({
    url: '/factory/product/line',
    method: 'post',
    successMsg: '新增成功',
    data,
    baseURL,
  });
}

/**删除工位 */
export function DelProductionLine(data: any) {
  return ajaxService({
    url: '/factory/product/line',
    method: 'delete',
    successMsg: '删除成功',
    data,
    baseURL,
  });
}

/**修改工位 */
export function EditProductionLine(data: typeObj.TbomBase) {
  return ajaxService({
    url: '/factory/product/line',
    method: 'post',
    data,
    successMsg: '修改成功',
    baseURL,
  });
}

/**修改工位 */
export function GetdFactorySet(params: any) {
  return ajaxService({
    url: '/factory/workshop/process',
    method: 'get',
    params,
    baseURL,
  });
}

/**新增工位
 * type = 1 工位工序
 */
export function AddFactorySet(data: any) {
  return ajaxService({
    url: '/factory/set',
    method: 'post',
    data,
    successMsg: '新增成功',
    baseURL,
  });
}

export function AddResources(data: any) {
  return ajaxService({
    url: '/factory/set/resources',
    method: 'post',
    data,
    successMsg: '新增成功',
    baseURL,
  });
}

export function DelResources(ids: any[]) {
  return ajaxService({
    url: '/factory/set/resources',
    method: 'delete',
    data: { ids },
    successMsg: '删除成功',
    baseURL,
  });
}

/**新增工位 */
export function DelFactorySet(ids: any[]) {
  return ajaxService({
    url: '/factory/set',
    method: 'delete',
    data: { ids },
    successMsg: '删除成功',
    baseURL,
  });
}

/**新增工位 */
export function GetProductIdBom(params: { id: number }) {
  return ajaxService({
    url: '/factory/product/bom/productId',
    method: 'get',
    params,
    baseURL,
  });
}
